import { SpaceInfoEntity } from '../entity/info';
import { Inject, Provide } from '@midwayjs/decorator';
import { BaseService, MODETYPE, CoolTransaction } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { PluginService } from '../../plugin/service/info';
import { QueryRunner } from 'typeorm';
/**
 * 文件信息
 */
@Provide()
export class SpaceInfoService extends BaseService {
  @InjectEntityModel(SpaceInfoEntity)
  spaceInfoEntity: Repository<SpaceInfoEntity>;

  @Inject()
  pluginService: PluginService;

  /**
   * 新增
   */
  @CoolTransaction({
    connectionName: 'default',
  })
  async add(param, queryRunner?: QueryRunner) {
    let {
      province,
      city,
      district,
    } = param;
    let sqlParams = param
    sqlParams.pca = province + '/' + city + '/' + district
    let data = await queryRunner.manager.insert<SpaceInfoEntity>(
      SpaceInfoEntity,
      sqlParams
    );
    console.log(sqlParams, 'sqlParams', data)
    return {
      id: sqlParams.id,
    };
  }

	async sqlPage(query) {
		return this.sqlRenderPage("select * from space_info ORDER BY id ASC", query, false);
	}

}
